package com.clean.cleantotal.pop

import android.animation.ValueAnimator
import android.content.Context
import android.widget.TextView
import com.airbnb.lottie.LottieAnimationView
import com.clean.cleantotal.R
import com.clean.cleantotal.bean.FunType
import com.clean.cleantotal.utils.Utils
import com.lxj.xpopup.core.BasePopupView

class PopScan(
    context: Context,
    private var funType: FunType?,
    private var callBack: (animal: ValueAnimator) -> Unit,
    private var finish: () -> Unit
) : BasePopupView(context) {
    override fun onCreate() {
        super.onCreate()
        val lottieAnimationView = findViewById<LottieAnimationView>(R.id.animal)
        val tvPer = findViewById<TextView>(R.id.tvPer)
        val tvContent = findViewById<TextView>(R.id.tvContent)

        when (funType) {
            FunType.DEVICE -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("device.json")
            }

            FunType.CLEAN -> {
                tvContent.text = "Scanning Mobile Phone ..."
//                lottieAnimationView.setAnimation("scan.json")
            }

            FunType.LARGE -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("large.json")
            }

            FunType.BATTERY -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("battery.json")
            }

            FunType.PROCESS -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("process.json")
            }

            FunType.EMPTY -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("file.json")
            }

            FunType.COMPRESS_IMAGE -> {
                tvContent.text = "Scanning Photos..."
                lottieAnimationView.setAnimation("image.json")
            }

            FunType.COMPRESS -> {
                tvContent.text = "Scanning Photos..."
                lottieAnimationView.setAnimation("compress.json")
            }

            FunType.TIK -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("tik.json")
            }

            FunType.INS -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("ins.json")
            }

            FunType.TEL -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("tele.json")
            }

            FunType.WHATSAPP -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("whats.json")
            }

            null -> {
                tvContent.text = "Scanning Mobile Phone ..."
                lottieAnimationView.setAnimation("scan.json")
            }

        }
        lottieAnimationView.playAnimation()
        val animal = Utils.showAnimalProcess(tvPer) {
            dismiss()
            finish.invoke()
        }
        callBack.invoke(animal)
    }

    override fun getInnerLayoutId(): Int {
        return R.layout.activity_scan
    }
}